<?php


namespace app\api\model;


use app\admin\model\ShoproStore;
use think\Model;

class GoodsServeModel extends Model
{
    // 表名,不含前缀
    protected $name = 'sendgoods_serve';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    protected $append = [
        'serve_time_text',
        'shop_name',
        'state_text'
    ];

    public function getStateTextAttr($val,$data)
    {
        $text = '';
        if($data['state'] == 0){
            $text = '取消';
        }
        if($data['state'] == 1){
            $text = '已预约';
        }
        if($data['state'] == 2){
            $text = '已核销';
        }
        return $text;
    }
    public function getShopNameAttr($val,$data)
    {
        $shop = ShoproStore::get($data['shop_id']);
        return $shop?$shop['name']:'';
    }

    public function getServeTimeTextAttr($val,$data)
    {
        if(!empty($data['serve_time'])){
            return date('Y-m-d H:i',$data['serve_time']);
        }
        return '';
    }
}
